package zhuyun.code

fun main(args:Array<String>){
    val classAdviser = ClassAdviser()
    val departmentHead = DepartmentHead()
    val dean = Dean()
    classAdviser.next = departmentHead
    departmentHead.next = dean
    classAdviser.handleRequest(9)
}
abstract class Leader{
    var next:Leader? = null
    abstract fun handleRequest(leaveDays:Int)
}
class ClassAdviser:Leader(){
    override fun handleRequest(leaveDays: Int) {
        if(leaveDays <= 2){
            println("班主任批准你请假${leaveDays}天")
        } else {
            if(next == null){
                println("请假天数太多，没有人批准该假条")
            } else {
                next?.handleRequest(leaveDays)
            }
        }
    }

}
class DepartmentHead:Leader(){
    override fun handleRequest(leaveDays: Int) {
        if(leaveDays<=7){
            println("系主任批准你请假${leaveDays}天")
        } else {
            if(next == null){
                println("请假天数太多，没有人批准该假条")
            } else {
                next?.handleRequest(leaveDays)
            }
        }
    }

}

class Dean:Leader(){
    override fun handleRequest(leaveDays: Int) {
        if(leaveDays<=10){
            println("院长批准你请假${leaveDays}天")
        } else{
            if(next == null){
                println("请假天数太多，没有人批准该假条")
            }else{
                next?.handleRequest(leaveDays)
            }
        }
    }

}